<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:gis="http://fgeorges.org/ns/google/issue"
                xmlns:gdata="http://fgeorges.org/ns/google/data"
                xmlns:atom="http://www.w3.org/2005/Atom"
                xmlns:os="http://a9.com/-/spec/opensearch/1.1/"
                xmlns:gd="http://schemas.google.com/g/2005"
                xmlns:issues="http://schemas.google.com/projecthosting/issues/2009"
                exclude-result-prefixes="#all"
                version="2.0">

   <xsl:import href="http://fgeorges.org/ns/google/gissue.xsl"/>

   <xsl:output indent="yes"/>

   <xsl:param name="user"    as="xs:string" required="yes"/>
   <xsl:param name="pwd"     as="xs:string" required="yes"/>
   <xsl:param name="project" as="xs:string" select="'expath'"/>

   <xsl:variable name="service" as="element(gdata:service)" select="
       gis:make-login-project-service($user, $pwd)"/>
   <xsl:variable name="issues"  as="element(atom:entry)+" select="
       gis:get-issues($service, $project)/atom:entry"/>

   <xsl:template name="main">
      <root>
         <xsl:call-template name="issues"/>
         <xsl:call-template name="labels"/>
      </root>
   </xsl:template>

   <xsl:template name="issues">
      <issues>
         <xsl:sequence select="$issues"/>
      </issues>
   </xsl:template>

   <!--
       TODO: It seems there is no API to get the label list, so we
       actually only extract those preseent in the issues we got.
   -->
   <xsl:template name="labels">
      <labels>
         <xsl:sequence select="distinct-values($issues/issues:label)"/>
      </labels>
   </xsl:template>

</xsl:stylesheet>
